<!-- subpkg_consult/department/department -->
<script lang="ts" setup>
import { departmentListApi } from '@/api/consult';
import type { DepartData } from '@/types/consult';
import { onLoad } from '@dcloudio/uni-app';
import { computed, ref } from 'vue';

/** 一级科室数据 */
const depList = ref<DepartData[]>([])
onLoad(async () => {
  //获取科室列表
  const res = await departmentListApi()
  depList.value = res
})

//获取二级科室数据
const selectIndex = ref(0)
const depChildList = computed(() => depList.value[selectIndex.value]?.child)

//获取路由参数
interface Props {
  type: number
  illnessType: number
}
defineProps<Props>()
</script>

<template>
  <view class="department-page">
    <scroll-view scroll-y class="department-primary">
      <view class="department-item" :class="{ active: selectIndex === index }" @click="selectIndex = index"
        v-for="(item, index) in depList" :key="item.id">{{ item.name }}</view>
    </scroll-view>
    <scroll-view class="department-secondary">
      <navigator hover-class="none"
        :url="`/subpkg_archive/description/description?type=${type}&illnessType=${illnessType}`" class="department-item"
        v-for="(item, index) in depChildList" :key="item.id">
        {{ item.name }}
      </navigator>
    </scroll-view>
  </view>
</template>

<style lang="scss">
@import 'department.scss';
</style>